﻿Shader "Custom/SelectiveBlurMask" 
{
	Properties 
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Color ("Base (RGB) Trans (A)", Color) = (1, 1, 1, 1)
		_Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
	}

	Category
	{
		
		LOD 100
		Lighting Off
		Fog
		{
			Mode Off
		}

		SubShader
		{
			Tags
			{
				"RenderType" = "Opaque"
				"Queue" = "Geometry"
				"IgnoreProjector" = "True"
			}

			Pass
			{
				CGPROGRAM
				
				#pragma vertex vert
				#pragma fragment frag
				#include "UnityCG.cginc"

				struct a2f
				{
					float4	vertex		:	POSITION;
					float4	texcoord	:	TEXCOORD0;
				};
				struct v2f
				{
					float4	pos			:	SV_POSITION;
					half2	uv			:	TEXCOORD0;
				};

				uniform sampler2D	_MainTex;
				uniform float4		_MainTex_ST;
				uniform fixed		_BlurAmount;

				v2f vert( a2f v )
				{
					v2f o;
					o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
					o.uv = TRANSFORM_TEX( v.texcoord, _MainTex );
					return o;
				}

				fixed4 frag( v2f i ) : COLOR
				{
					return fixed4( _BlurAmount.xxx, 1 );
				}
				ENDCG
			}
		}



		SubShader {
			Tags {"RenderType" = "TransparentCutout" "Queue" = "AlphaTest" "IgnoreProjector" = "True"}
			Pass {
				CGPROGRAM
					#pragma vertex vert
					#pragma fragment frag
					#include "UnityCG.cginc"

					struct a2f {
						float4 vertex : POSITION;
						float4 texcoord : TEXCOORD0;
					};
					struct v2f {
						float4 Pos : SV_POSITION;
						half2 Uv : TEXCOORD0;
					};

					uniform sampler2D _MainTex;
					uniform float4 _MainTex_ST;
					uniform fixed _Cutoff;
					uniform fixed4 _Color;
					uniform fixed _BlurAmount;

					v2f vert(a2f v) {
						v2f o;
						o.Pos = mul(UNITY_MATRIX_MVP, v.vertex);
						o.Uv = TRANSFORM_TEX(v.texcoord, _MainTex);
						return o;
					}
					fixed4 frag(v2f i) : COLOR {
						fixed4 col = tex2D(_MainTex, i.Uv);
						clip(col.a * _Color.a - _Cutoff);
						return fixed4(_BlurAmount.xxx, 1);
					}
				ENDCG
			}
		}

		SubShader 
		{
			Tags {"RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True"}
			Pass {

				Alphatest Greater 0
				ZWrite Off
				Blend SrcAlpha OneMinusSrcAlpha
				ColorMask RGB

				CGPROGRAM
					#pragma vertex vert
					#pragma fragment frag
					#include "UnityCG.cginc"

					struct a2f {
						float4 vertex : POSITION;
						float4 texcoord : TEXCOORD0;
					};
					struct v2f {
						float4 Pos : SV_POSITION;
						half2 Uv : TEXCOORD0;
					};

					uniform sampler2D _MainTex;
					uniform float4 _MainTex_ST;
					uniform fixed4 _Color;
					uniform fixed _BlurAmount;

					v2f vert(a2f v) {
						v2f o;
						o.Pos = mul(UNITY_MATRIX_MVP, v.vertex);
						o.Uv = TRANSFORM_TEX(v.texcoord, _MainTex);
						return o;
					}
					fixed4 frag(v2f i) : COLOR {
						fixed4 col = tex2D(_MainTex, i.Uv);
						float alpha = col.a * _Color.a;
						return fixed4(_BlurAmount.xxx, alpha);
					}
				ENDCG
			}
		}


	}	
	
}
